<template>
    <view class="content">
        <Banner :data="banner" />
    </view>
</template>

<script>
    import Banner from 'components/Banner';
    export default {
        name: 'index',
        components: { Banner },
        filters: {},
        data() {
            return {
                banner: []
            };
        },
        methods: {
            async onLoad(options) {
                console.log('onLoad');
                await this.initData();
                this.banner = [{ image: 'https://cdn.uviewui.com/uview/swiper/swiper1.png', path: '0' },
                               { image: 'https://cdn.uviewui.com/uview/swiper/swiper1.png', path: '1' },
                               { image: 'https://cdn.uviewui.com/uview/swiper/swiper1.png', path: '2' }];
            },
            async initData() {
            },
            onShareAppMessage () {
                return {
                    title: '主页',
                    path: '/pages/index/index'
                };
            },
            async fetchOrderList() {
                const data = []; // await getListSchoolEvent(this.schoolInfo.schoolId, (this.currentPage - 1) * this.pageSize, this.pageSize);
                this.orderList = this.orderList.concat(data);
            },
            async refreshOrderData() {
                this.currentPage = 1;
                this.orderList = [];
                await this.fetchOrderList();
            },
            async onPullDownRefresh() {
                await this.initData();
                uni.stopPullDownRefresh();
            },
            async onReachBottom() {
                this.currentPage++;
                await this.fetchOrderList();
            },
            handleSwiperClick(item) {
                const linkUrl = item.path;
                if (!linkUrl) return;
                if (linkUrl && linkUrl.indexOf('miniprogram://') !== -1) {
                    const url = linkUrl.substring(14, linkUrl.length);
                    console.log(url);
                    uni.navigateTo({
                        url: '/' + url,
                        fail(err) {
                            console.error(err);
                        }
                    });
                } else if (linkUrl.indexOf('web://') !== -1) {
                    const encoded64Url = Buffer.from(linkUrl.substring(6, linkUrl.length)).toString('base64');
                    uni.navigateTo({
                        url: '/pages/webview/index?url=' + encoded64Url,
                        fail(err) {
                            console.error(err);
                        }
                    });
                } else if (linkUrl.indexOf('third://') !== -1) {
                    const strArray = linkUrl.split('#');
                    uni.navigateToMiniProgram({
                        appId: strArray[0].substring(8),
                        path: strArray[1],
                        envVersion: 'release'
                    });
                }
            }
        }
    };
</script>

<style lang="scss">
@import "../../styles/global.scss";
.content {
    background-color: #f4f4f4;
}
</style>
